<?php
class cls_data_productlist extends cls_data_base
{
	function get_product_list($product_category)
	{
		$product_category=mysql_escape_string($product_category);
		//$start=8*($current_page-1);
		$sql = "select p.id,p.name,p.author,p.image,d.discounttype,d.amount,p.price 
				from product p 
					left join discountproduct dp on dp.productid = p.id
					left join discount d on d.id=dp.discountid
				where p.category='{$product_category}'";
		$product_list=$this->db->getAll($sql);
		//print_r($sql);
		return $product_list;		
	}
	
	function get_product_list_top4($product_category)
	{
		$product_category=mysql_escape_string($product_category);
		$sql = "select top 4 p.id,p.name,p.author,p.image,d.type,d.amount,p.price
		from product p
		left join discountproduct dp on dp.productid = p.id
		left join discount d on d.id=dp.discountid
		where p.category='{$product_category}'
		order by p.id acs
		limit 0,4;
		";
		$product_list=$this->db->getAll($sql);
		return $product_list;
	}
	
	function get_category_level($product_category)
	{
		$product_category=mysql_escape_string($product_category);
		$sql="select lvl from categorytype where id='{$product_category}'";
		$category_level = $this->db->getRow($sql);
		return $category_level;		
	}
	
	function get_category_child($product_category)
	{
		$product_category=mysql_escape_string($product_category);
		$sql="select cr.childid from categoryrelation cr,categorytype c where c.id='{$product_category}' and c.id=cr.parentid";
		$product_category=$this->db->getCol($sql);
		return $product_category;
	}
	
	function get_category_parent($product_category)
	{

		$product_category=mysql_escape_string($product_category);
		$sql="select cr.parentid from categoryrelation cr,categorytype c where c.id='{$product_category}' and c.id=cr.childid";
		$product_category=$this->db->getCol($sql);
		return $product_category;
	}
	
	function get_category_name($product_category)
	{
		$product_category=mysql_escape_string($product_category);
		$sql="select name from categorytype where id='{$product_category}'";
		$category_name=$this->db->getOne($sql);
		return $category_name;
	}
	
	function get_product_info($product_id)       /*输入产品id， 输出product表里的关于该产品的所有信息 */
	{
		$product_id=mysql_escape_string($product_id);
		$sql="select p.*,ps.Quantity
		from product p
		left join productstatistic ps on p.ID=ps.productID
		where p.ID='{$product_id}'";
		$product_detail=$this->db->getrow($sql);
		return $product_detail;
	}
	
	function get_product_discount($product_id)
	{
		$product_id=mysql_escape_string($product_id);
		$sql="select d.* from
		discountproduct dp,discount d
		where d.ID = dp.DiscountID and dp.productid='{$product_id}'";
		$product_discount=$this->db->getrow($sql);
		return $product_discount;
	}
	
	function get_original_category()
	{
		$sql="select id from categorytype where lvl=0";
		$original_category=$this->db->getall($sql);
		return $original_category;
	}
	
}